feat: handle device event in service handler#132
Open
vthib wants to merge 1 commit into
Open
Conversation
Add device event in service control to allow the user to receive and handle device events. The data of those events is for the moment not parsed. Converting those events to Rust is not trivial, and we can let the user do it rather than doing it in his place, when he does not necessarily care for all the different type of device events.
pronebird
reviewed
Feb 24, 2025
| /// <https://learn.microsoft.com/en-us/windows/win32/devio/wm-devicechange>. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| #[non_exhaustive] | ||
| pub enum DeviceEventParam { |
Contributor
There was a problem hiding this comment.
Given that each variant contains *const c_void, would it make sense to represent that as a struct with two fields instead?
Contributor
Author
There was a problem hiding this comment.
That would be quite equivalent yes, except that it would remove the possibility to add safe wrappers for some of those events in the future
pronebird
reviewed
Mar 7, 2025
Contributor
pronebird
left a comment
There was a problem hiding this comment.
Reviewed all commit messages.
Reviewable status: 0 of 1 files reviewed, all discussions resolved
pronebird
reviewed
Mar 7, 2025
Contributor
pronebird
left a comment
There was a problem hiding this comment.
Reviewed 1 of 1 files at r1.
Reviewable status:complete! all files reviewed, all discussions resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have recently needed to receive device events as a windows service, and found out that I couldn't with the current version of windows-service. This PR is here to make this possible.
To receive those events, a call to
RegisterDeviceNotificationmust be done. This is of course not done in this crate and let instead to the user.Then, instead of parsing the event data for every subtype of device events, I've chosen to keep the event data in raw form, and let the user of the crate do this parsing. This does not seem to be quite how the rest of the service event handler is written, but this is by far the simplest:
RegistryDeviceNotificationSo all in all, it's imho much simpler and also efficient to let the user handle the conversion of this event data into rust. For example in my case, I only need to handle device arrival, and only some subset of those events.
Let me know what you think, or if you would prefer parsing those events to provide a nicer experience to the user. Also, thanks for your work on this crate :)
This change is